package com.yihu.cms.service;

import java.io.IOException;
import java.net.MalformedURLException;

import com.yihu.beans.ArtworkDescription;
import com.yihu.dataService.hessian.mongodb.interfaceService.ArtworkDescriptionHService;
import com.yihu.dataService.hessian.resource.ResourceMongoDBManager;

public class ArtworkDescriptionService {

	public int add(ArtworkDescription artworkDescription) {
		int result = 0;
		try {
			ArtworkDescriptionHService artworkDescriptionHService = (ArtworkDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("artworkDescriptionHSC");
			result = artworkDescriptionHService.addArtworkDescription(artworkDescription);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 1;
			e1.printStackTrace();
		}
		return result;
	}
	
	public int del(long id) {
		int result = 0;
		try {
			ArtworkDescriptionHService artworkDescriptionHService = (ArtworkDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("artworkDescriptionHSC");
			result = artworkDescriptionHService.delArtworkDescription(id);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 1;
			e1.printStackTrace();
		}
		return result;
	}
	
	public int update(ArtworkDescription artworkDescription) {
		int result = 0;
		try {
			ArtworkDescriptionHService artworkDescriptionHService = (ArtworkDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("artworkDescriptionHSC");
			result = artworkDescriptionHService.updateArtworkDescription(artworkDescription);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 1;
			e1.printStackTrace();
		}
		return result;
	}
	
	public ArtworkDescription getById(long id) {
		ArtworkDescription artworkDescription = null;
		try {
			ArtworkDescriptionHService artworkDescriptionHService = (ArtworkDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("artworkDescriptionHSC");
			artworkDescription = artworkDescriptionHService.getArtworkDescriptionById(id);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
//			result = 1;
			e1.printStackTrace();
		}
		return artworkDescription;
	}
	
	
}
